﻿using System;
using Wintellect.PowerCollections;
using System.Collections.Generic;

namespace PriorityQueue
{
    class PriorityQueue<T>:IEnumerable<T>,ICollection<T> where T:IComparable<T>
    {
        private OrderedBag<T> data;

        public PriorityQueue()
        {
            data = new OrderedBag<T>();
        }

        public IEnumerator<T> GetEnumerator()
        {
            return data.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        public void Add(T item)
        {
            data.Add(item);
        }

        public void Clear()
        {
            data.Clear();
        }

        public bool Contains(T item)
        {
            return data.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            data.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get 
            {
                return data.Count;
            }
        }

        public bool IsReadOnly
        {
            get 
            {
                return false;
            }
        }

        public bool Remove(T item)
        {
            return data.Remove(item);
        }

        public T Dequeue()
        {
            T result = data.GetFirst();
            Remove(result);
            return result;
        }

        public T Top()
        {
            T result = data.GetFirst();
            return result;
        }
    }
}
